<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href='<?php echo base_url()?>'>
<link rel="stylesheet" type="text/css" href="public/common/css/common.css"/>
<link rel="stylesheet" type="text/css" href="public/admin/css/admin.css"/>
<script src="public/common/js/jquery.js"></script>
<script>
$(function(){
	$('.table tr').hover(function(){
		$(this).children('td').css('background','#ccffcc');
	},function(){
		$(this).children('td').css('background','white');
	});	
	get_ad();
});
function get_ad()
{
	category_id = $('select[name="cate_id"]').val();
	$.post('<?php echo site_url("admin/ad/get_ad")?>',{category_id:category_id},function(result){
		html='<tr><th>广告图片</th><th>链接地址</th><th>文字说明</th><th>排序</th><th>操作</th></tr>';
		if(result == '0')
		{
			html+='<tr><td colspan=5 align=center>该分类下没有任何广告!</td></tr>';
			$('.table').html(html);
		}else{
			result_obj = eval('('+result+')');
			for(var i=0;i<result_obj.length;i++)
			{
				html += '<tr><td class="center"><a alt="点击查看图片" title="点击查看图片" style="color:black;" href="'+result_obj[i].ad_img+'" target="_blank">'+result_obj[i].ad_img+'</a></td><td class="center">'+result_obj[i].ad_link+'</td><td class="center">'+result_obj[i].ad_desc+'</td><td class="center">'+result_obj[i].ad_sort+'</td><td class="center"><a href="<?php echo site_url("admin/ad/ad_edit")?>/'+result_obj[i].ad_id+'">修改</a> | <a href="javascript:void(0)" onclick="delete_ad(this,'+result_obj[i].ad_id+')">删除</a></td></tr>';
			}
			$('.table').html(html);

		}
	});
}
function delete_ad(obj,ad_id)
{
	$.post('<?php echo site_url("admin/ad/delete_ad")?>',{ad_id:ad_id},function(result){
		if(result == 1)
		{
			$(obj).parent().parent().remove();
		}else{
			alert('删除失败！');
		}
	});
}
</script>
</head>
<body>
	<div class="body">
    	<?php echo $this->position->get_position();?>
    	<div class="body_center">
        	<div class="list_sl_btn">
                <ul>
				<li>请选择分类：
				<select name="cate_id" style="width:200px; margin-top:2px;" onchange='get_ad()'>
					<?php foreach($category->result() as $value):?>
					<option value="<?php echo $value->category_id?>"><?php echo $value->category_name?></option>
					<?php endforeach;?>
				</select>
				</li>
                </ul>
			</div>
            <table class="table" style="margin-bottom:0px;"></table>
        </div>
    </div>
</body>
</html>